//
//  SalaryQuaryResultVC.m
//  FindJob
//
//  Created by 233 on 16/3/7.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "SalaryQuaryResultVC.h"
#include "SalaryQuaryAPIManger.h"
#import "BarChartView.h"

@interface SalaryQuaryResultVC ()<BarChartViewDataSource>
@property(nonatomic,strong)SalaryQuaryAPIManger *salaryQuaryAPIManger;
@property(nonatomic,copy)NSDictionary *dataDict;
@property(nonatomic,strong)BarChartView *chartView;

- (void)initializeDataSource;/**< 初始化数据源 */

@end

@implementation SalaryQuaryResultVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    
}
#pragma mark -- private
- (void)initializeDataSource{
    NSDictionary *paprameter = @{@"area":self.requstArr[0],@"functions":self.requstArr[1],@"industry":self.requstArr[2],@"workExperience":self.requstArr[3]};
    [self.salaryQuaryAPIManger startSalaryQuaryRequestWithPaprameters:paprameter responds:^(RespondsStatus status, NSString *message, id reslut) {
        if (status==RespondsStatusSuccess) {
            self.dataDict = reslut;
           [self.view addSubview:self.chartView];
            [self.chartView reloadDatas];
        }
    }];
    
}
#pragma mark -- <BarChartViewDataSource>
- (NSUInteger)numberOfBarsInBarChartView:(BarChartView *)barChartView{
    return self.dataDict.count;
}
- (BarModel *)barChartView:(BarChartView *)barChartView barModelInRow:(NSInteger)row{
    BarModel *barModel = [[BarModel alloc] init];
    if (row == 0) {
         barModel.title = @"最低";
        barModel.value = [self.dataDict[@"minSalary"] floatValue];
    }else{
        barModel.title = @"最高";
        barModel.value = [self.dataDict[@"maxSalary"] floatValue];
    }
    barModel.barColor = [UIColor grayColor];
    return barModel;
   
}
#pragma mark -- getters
- (SalaryQuaryAPIManger *)salaryQuaryAPIManger{
    if (!_salaryQuaryAPIManger) {
        _salaryQuaryAPIManger = [[SalaryQuaryAPIManger alloc] init];
    }
    return _salaryQuaryAPIManger;
}
- (BarChartView *)chartView{
    if (!_chartView) {
        _chartView = [[BarChartView alloc] initWithFrame:CGRectMake(20, 50, 200, 300)];
        _chartView.leftSpacing = 20;
        _chartView.rightSpacing = 20;
        _chartView.barsSpacing = 50;
        _chartView.maxValue = 10000;
        _chartView.minValue = 1000;
        _chartView.dataSource = self;
        _chartView.backgroundColor = [UIColor yellowColor];
    }
    return _chartView;
}
@end
